import SDKHelper from "../core/sdk/SDKHelper";
import Global1 from "../script/http/Global1";
import { Http1 } from "../script/http/Http1";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Launch extends cc.Component {

    @property(cc.Node)
    logoNode: cc.Node = null;

    onLoad() {
        this.logoNode.opacity = 0;
        SDKHelper.Instance.initSdk();
    }

    start() {
        this.playLogoAnima();
        // if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
        //     SDKHelper.Instance.subpackage('resources', (is1: boolean) => {
        //         if (is1) {
        //             SDKHelper.Instance.subpackage('res', (is2: boolean) => {
        //                 if (is2) {
        //                     // cc.director.loadScene('main');
        //                 }
        //             })
        //         }
        //     })
        // }
    }

    private playLogoAnima() {
        cc.tween(this.logoNode)
            .to(2, { opacity: 255 })
            .delay(0.5)
            .call(() => {
                // if (cc.sys.platform !== cc.sys.BYTEDANCE_GAME) {
                //     // cc.director.loadScene('main');
                // }
                Http1.post("/Login/doLogin", { platform: "cs", openid: "91a66623fcdb604da56a41bcded222b1", user_info: "", code: "" }, (data) => {

                    Global1.token = data.token;
                    console.log(Global1.token);

                    Http1.post("/user/info", {}, (data) => {
                        Global1.userInfo = data
                        cc.director.loadScene('main');
                    }, this)
                }, this)


            })
            .start()
    }

    // update (dt) {}
}
